package com.zl.quickdoc.resolver.converter.impl;

import com.zl.quickdoc.constant.QuickDocC;
import com.zl.quickdoc.resolver.converter.AbstractJavaDocTag;

/**
 * 针对@contentType的转换器
 * @author zhouliang
 *
 */
public class ContentTypeTagConverter extends DefaultStringParserTagConverterImpl {

    @SuppressWarnings("unchecked")
    @Override
    public AbstractJavaDocTag<String> converter(String comments) {
        AbstractJavaDocTag<String> docTag = super.converter(comments);
        String val = docTag.getValues();
        return new ContentTypeTagImpl(docTag.getTagName(), val);
    }
    
    public class ContentTypeTagImpl extends AbstractJavaDocTag<String> {

        /**
         * 类型值
         */
        private String value;

        public ContentTypeTagImpl(String tagName, String value) {
            super(tagName);
            this.value = value;
        }

        @Override
        public String getValues() {
            if(QuickDocC.SIMPLE_TYPE_JSON.equalsIgnoreCase(this.value)){
                return QuickDocC.TYPE_JSON;
            }
            else if(QuickDocC.SIMPLE_TYPE_FORM_DATA.equalsIgnoreCase(this.value)){
                return QuickDocC.TYPE_FORM_DATA;
            }
            else if(QuickDocC.SIMPLE_TYPE_FORM_URLENCODED.equalsIgnoreCase(this.value)){
                return QuickDocC.TYPE_FORM_URLENCODED;
            }
            else if(QuickDocC.SIMPLE_TYPE_XML.equalsIgnoreCase(this.value)){
                return QuickDocC.SIMPLE_TYPE_XML;
            }
            return this.value;
        }
    }
}
